import Vue from "vue";
import VueRouter from "vue-router";

// 导入需要配置的路由组件
import login from '../components/login.vue'
import home from '../components/home.vue'
import pest from '../components/pest.vue'
import disease from '../components/disease.vue'
import pestInfo from '../components/pestInfo.vue'
import addPest from '../components/addPest.vue'
import diseaseInfo from '../components/diseaseInfo.vue'
import addDisease from '../components/addDisease.vue'
import mouse from '../components/mouse.vue'
import mouseInfo from '../components/mouseInfo.vue'
import addMouse from '../components/addMouse.vue'
import area from '../components/area.vue'
import addArea from '../components/addArea.vue'
import classes from '../components/classes.vue'
import addClass from '../components/addClass.vue'
import classInfo from '../components/classInfo.vue'
import updateClass from '../components/updateClass.vue'
import thing from '../components/thing.vue'
import addThing from '../components/addThing.vue'
import thingInfo from '../components/thingInfo.vue'
import updateThing from '../components/updateThing.vue'

Vue.use(VueRouter)

// 创建常量 配置路由和组件的映射
const routes = [
   // {path:'url',component:组件} 
   {path:"/login",component:login},
   {path:"/home",component:home,
    children:[
        {path:"/home/pest",component:pest},
        {path:"/home/disease",component:disease},
        {path:"/home/pestInfo",component:pestInfo},
        {path:"/home/addPest",component:addPest},
        {path:"/home/diseaseInfo",component:diseaseInfo},
        {path:"/home/addDisease",component:addDisease},
        {path:"/home/mouse",component:mouse},
        {path:"/home/mouseInfo",component:mouseInfo},
        {path:"/home/addMouse",component:addMouse},
        {path:"/home/area",component:area},
        {path:"/home/addArea",component:addArea},
        {path:"/home/classes",component:classes},
        {path:"/home/addClass",component:addClass},
        {path:"/home/classInfo",component:classInfo},
        {path:"/home/updateClass",component:updateClass},
        {path:"/home/thing",component:thing},
        {path:"/home/addThing",component:addThing},
        {path:"/home/thingInfo",component:thingInfo},
        {path:"/home/updateThing",component:updateThing},
    ]    
}]

//核心：解决代码冗余
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 建立router对象
export default new VueRouter({
    mode:'history',
    routes
})